import jwt from 'jsonwebtoken';
import login from "../../dataAccess/login";
const loginServer = async (req: Request) => {
  const user =  await login(req);
  if (user) {
    const secretKey = 'your_secret_key'; 
    const token = jwt.sign({ id: user._id, userName: user.userName }, secretKey, { expiresIn: '1h' });
    user.token = token;
    await user.save(); // 更新token
    return {
      code: 200,
      message: "登录成功",
      token
    };
  }else {
    return {
      code: 0,
      message: "用户名或密码错误"
    };
  }
}
export default loginServer;